﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ReverseMarkdown;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        string patternP = @"<p.*?>";
        string patternSpan = "<span.*?span>";
        string pattern = @"<\/p>";

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            string e0 = inputE0.Text;
            string e1 = inputE1.Text;
            string e2 = inputE2.Text;
            string e3 = inputE3.Text;
            var contextHtml =
                WeCheatDecrypt.Decrypt(WeCheatDecrypt.Chk(e0) + WeCheatDecrypt.Chk(e1) + WeCheatDecrypt.Chk(e3));
            var cssContext = WeCheatDecrypt.Decrypt(WeCheatDecrypt.Chk(e2));
            txtPart1.Text = contextHtml;
            txtPart2.Text = cssContext;
            var converter = new Converter();
            string markdown = converter.Convert(contextHtml);
            markdown=markdown.Replace("(../Images/m1-note.png)", "");
            markdown=markdown.Replace("![","^[");
            markdown=markdown.Replace("^[]","![]");
            markdown = markdown.Replace("    ", "");
            // 正则表达式匹配 Markdown 图片链接
            string imagePattern = @"!\[.*?\]\(.*?\)";
            // 正则表达式匹配 Markdown 脚注
            string footnotePattern = @"\^\[.*?\](\: .*?$)?";

            // 替换掉图片链接和脚注
            string replacedMarkdown = Regex.Replace(markdown, imagePattern, "");
            replacedMarkdown = Regex.Replace(replacedMarkdown, footnotePattern, "", RegexOptions.Multiline);
            // 正则表达式匹配圆括号及其内部的内容
            string pattern = @"（.*?）";
            // 替换掉圆括号及其内部的文字
            replacedMarkdown = Regex.Replace(replacedMarkdown, pattern, "");

            txtPart3.Text = markdown;
            txtPart4.Text = replacedMarkdown;
        }
    }
}